﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class frmManageRequestDetail : System.Web.UI.Page
    {

        LogicUniversityT2Entities ct = new LogicUniversityT2Entities();
        string a = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            a = Request.Params["ID"];
          //  string a = Request.QueryString["RequisitionID"];
         //   string a = Request.Form["param"];  


    
            var select = from er in ct.EmployeeRequisitions

                         join erd in ct.EmployeeRequisitionDetails on er.EmployeeRequisitionID equals erd.EmployeeRequisitionID
                         join it in ct.Items on erd.ItemID equals it.ItemID
                         join itd in ct.ItemDetails on it.ItemID equals itd.ItemID
                         join cat in ct.Categories on it.CategoryID equals cat.CategoryID
                         where er.EmployeeRequisitionID == a
            
                             group ct.EmployeeRequisitions by new { 
                                 erd.EmployeeRequisitionID, 
                                 er.EmployeeRequisitionDate,
                                 erd.ItemID,
                                 cat.CategoryName,
                                 it.ItemDescription, 
                                 erd.RequestedQuantity,
                                 itd.Price,
                                 er.TotalAmount 
                             } into abc



                         select new

                         {
                             RequisitionID = abc.Key.EmployeeRequisitionID,
                             RequisitonDate = abc.Key.EmployeeRequisitionDate,
                             ItemID = abc.Key.ItemID,
                             Cate = abc.Key.CategoryName,
                             Des = abc.Key.ItemDescription,
                             Qty = abc.Key.RequestedQuantity,
                             Price = abc.Key.Price,
                             TotalAmount = abc.Key.TotalAmount
                         };


            var list = select.ToList();

            gvManageReqDetail.DataSource = list;
            gvManageReqDetail.DataBind();

            Label2.Text = list.First().RequisitionID.ToString();
            Label3.Text = list.First().RequisitonDate.ToString();
            Label4.Text = list.First().TotalAmount.ToString();  


        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("frmManageRequest.aspx");
        }

        protected void btnReject_Click(object sender, EventArgs e)
        {
              
          EmployeeRequisition select = (from er in ct.EmployeeRequisitions
                         where er.EmployeeRequisitionID == a

                          select er).FirstOrDefault<EmployeeRequisition>();

            select.Status="Reject";

            ct.SaveChanges();
         //SendEmail Method 
            
                        
        }
    }
}